<?php
	include_once "xAP-functions/webincludes.php";

$id=intval($_GET["id"]);


if($_GET["cat"]!=""){
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID
			where a.Category='".dbesc($_GET["cat"])."' 
			
			order by s.datestamp DESC limit 20";
}elseif($_GET["tag"]!=""){
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID INNER JOIN xAP_News_Story_Tag as tg ON
			tg.StoryID=s.StoryID
			where tg.Tag='".dbesc($_GET["tag"])."' 
			
			order by s.datestamp DESC limit 20";
}elseif($id==0){
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID order by s.datestamp DESC limit 20";
}else{
	$sql="select a.Alias,s.StoryID,s.DateStamp,s.Title,a.SourceID from 
			xAP_News_Story as s  INNER JOIN  xAP_News_Source as a ON
			a.SourceID=s.SourceID 
			where s.SourceID=".$id."
			order by s.datestamp DESC limit 20";
}
$results=dbquery($sql);

$q="?";
header("Content-type: text/xml");
?>
<<?=$q?>xml version="1.0" encoding="UTF-8"?>
<root>

<title set="waNewsStories">Latest</title>
<part>
<destination mode="replace" zone="waNewsStories" create="true"/>
<data><![CDATA[
<div class="iMenu">
<UL class='iArrow'>
<? foreach($results as $v):?>
<LI class='iArrow'><a href='/News/iphone_story.php?id=<?=$v["StoryID"]?>#_NewsStory' rev="async"><?=$v["Title"];?></a></LI>
<? endforeach; ?>
</UL>
</div>
]]></data>
</part>
</root>